package com.conversationboard.view;

import com.conversationboard.config.Configuration;
import com.conversationboard.model.User;

public class MessageAdminLinksDisplay {

    public static void includeAdminLinks(StringBuilder buffer, int boardId, int threadId, int messageId, boolean firstMessage, String userId, String ipAddress, User currentUser) {

        buffer.append("<div class='adminlinks' align=right>");

        /* You can't delete the first message; just the entire thread. I don't know if I like the logic here, as it's dependent on the database's autonumbering
         * functionality. Maybe look at this again, but it will do for now. */

        if (!firstMessage) {
            buffer.append("<a class=\"adminlink\" href='" + Configuration.getInstance().getRoot() + "/Pages/Admin/confirm.jsp?action=deletemessage&amp;boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;messageid=" + messageId
                    + "'>Delete</a> ");
            buffer.append("<a class=\"adminlink\" href='" + Configuration.getInstance().getRoot() + "/Pages/Admin/confirm.jsp?action=undeletemessage&amp;boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;messageid="
                    + messageId + "'>Undelete</a> ");
        }

        /* Only let site admins edit messages */

        if (currentUser.isSiteAdmin()) {
            buffer.append("<a class=\"adminlink\" href='" + Configuration.getInstance().getRoot() + "/Admin/AdminEditMessageControllerServlet?boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;messageid=" + messageId
                    + "'>Edit</a> ");
        }

        if (userId != null) {
            buffer.append("<a class=\"adminlink\" href='" + Configuration.getInstance().getRoot() + "/Pages/Admin/confirm.jsp?action=banuserfromthread&amp;boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;loginId=" + userId + "'><span class='amber'>Ban/Thread</span></a> ");
            buffer.append("<a class=\"adminlink\" href='" + Configuration.getInstance().getRoot() + "/Pages/Admin/confirm.jsp?action=unbanuserfromthread&amp;boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;loginId=" + userId + "'><span class='amber'>Unban/Thread</span></a> ");
            buffer.append("<a class=\"adminlink\" href=\"" + Configuration.getInstance().getRoot() + "/Pages/Admin/banuser.jsp?userid=" + userId + "&amp;boardid=" + boardId + "\"><span class='red'>Ban</span></a> ");
        }

        buffer.append("<a class=\"adminlink\" href=\"" + Configuration.getInstance().getRoot() + "/Admin/AdminUserInfoControllerServlet?boardid=" + boardId + "&amp;userid=" + userId + "\">User Info</a> ");
        buffer.append("<a class=\"adminlink\" href=\"" + Configuration.getInstance().getRoot() + "/Pages/Admin/confirmyellowcard.jsp?boardid=" + boardId + "&amp;threadid=" + threadId + "&amp;messageid=" + messageId + "&amp;loginid=" + userId + "\"><span class='amber'>Yellow Card</span></a>");

        if (messageId != 1) {
            buffer.append("<input type=\"checkbox\" name=\"checkbox\" value=\"" + messageId + "\" />");
        }

        buffer.append("</div>");

    }

}
